﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace LED_Tester
{
    public partial class frmSetAxsi : Form
    {
        public frmSetAxsi()
        {
            InitializeComponent();
        }

        private double yMin;
        private double yMax;

        public double YMin
        {
            get { return yMin; }
            set { yMin = value; }
        }
        public double YMax
        {
            get { return yMax; }
            set { yMax = value; }
        }

        #region 功能函数

        private static void TxtDataVerifyWithOnePoint(KeyPressEventArgs e, TextBox txt)
        {
            int pointCount = 0;
            bool isPointExist = false;
            if (char.IsNumber(e.KeyChar) || e.KeyChar == '.' || e.KeyChar == (char)Keys.Back)
            {
                e.Handled = false;
                if (txt.Text.Length == 0)
                {
                    if (e.KeyChar == '.')
                        e.Handled = true;
                }

                for (int i = 0; i < txt.Text.Length; i++)
                {
                    if (e.KeyChar == '.')
                        pointCount++;
                    if (pointCount > 1)
                        isPointExist = true;
                }

                if (isPointExist && e.KeyChar == '.')
                    e.Handled = true;
            }

            else { e.Handled = true; }
        }

        #endregion

        #region 窗体事件

        private void frmSetAxsi_Load(object sender, EventArgs e)
        {
            textBox1.Text = yMin.ToString("#0");
            textBox2.Text = YMax.ToString("#0");
        }

        #endregion

        #region 其它事件

        private void button1_Click(object sender, EventArgs e)
        {
            yMin = double.Parse(textBox1.Text);
            yMax = double.Parse(textBox2.Text);

            if (yMax <= yMin)
            {
                MessageBox.Show("请输入正确数值！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            else
            {
                DialogResult = DialogResult.OK;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            TxtDataVerifyWithOnePoint(e, textBox1);
        }

        private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
        {
            TxtDataVerifyWithOnePoint(e, textBox2);
        }

        #endregion
    }
}
